<?php

/**
 * This is the model class for table "fitofarmaco".
 *
 * The followings are the available columns in table 'fitofarmaco':
 * @property string $id
 * @property string $metodo_acao_id
 * @property string $nome
 * @property string $tipo_formulação
 * @property string $descricao
 * @property string $ficha_tecnica
 * @property integer $active
 * @property string $created_at
 * @property string $updated_at
 */
class Fitofarmaco extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Fitofarmaco the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'fitofarmaco';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('metodo_acao_id, nome, tipo_formulação, descricao, ficha_tecnica', 'required'),
            array('active', 'numerical', 'integerOnly' => true),
            array('metodo_acao_id', 'length', 'max' => 10),
            array('nome', 'length', 'max' => 255),
            array('created_at, updated_at', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, metodo_acao_id, nome, tipo_formulação, descricao, ficha_tecnica, active, created_at, updated_at', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'produtos' => array(self::MANY_MANY, 'Produto', 'produto_fitofarmaco(fitofarmaco_id,produto_id)'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'metodo_acao_id' => 'Metodo Acao',
            'nome' => 'Nome',
            'tipo_formulação' => 'Tipo Formulação',
            'descricao' => 'Descricao',
            'ficha_tecnica' => 'Ficha Tecnica',
            'active' => 'Active',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('metodo_acao_id', $this->metodo_acao_id, true);
        $criteria->compare('nome', $this->nome, true);
        $criteria->compare('tipo_formulação', $this->tipo_formulação, true);
        $criteria->compare('descricao', $this->descricao, true);
        $criteria->compare('ficha_tecnica', $this->ficha_tecnica, true);
        $criteria->compare('active', $this->active);
        $criteria->compare('created_at', $this->created_at, true);
        $criteria->compare('updated_at', $this->updated_at, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}
